#include"Stack.h"
void StInit(Stack* ps) {
	assert(ps);
	ps->arr = NULL;
	ps->capacity = ps->size = 0;
}
void StPush(Stack* ps, int x) {
	assert(ps);
	if (ps->capacity == ps->size) {
		int newCapacity = ps->capacity == 0 ? 4 : ps->capacity * 2;
		int* tmp = (DataType*)realloc(ps->arr, sizeof(DataType) * newCapacity);
		if (tmp == NULL) {
			perror("realloc fail");
			exit(1);
		}
		ps->arr = tmp;
		ps->capacity = newCapacity;
	}
	ps->arr[ps->size++] = x;
}
void StPop(Stack* ps) {
	assert(ps);
	assert(ps->size);
	ps->size--;
}
int StTop(Stack* ps) {
	assert(ps);
	assert(ps->size);
	return ps->arr[ps->size - 1];
}
bool StEmpty(Stack* ps) {
	assert(ps);
	return ps->size == 0;
}
void StDestroy(Stack* ps) {
	assert(ps);
	if (ps->arr)free(ps->arr);
	ps->capacity = ps->size = 0;
}
void StPrint(Stack st) {
	for (int i = 0; i < st.size; i++) {
		printf("%d ", st.arr[i]);
	}
	printf("\n");
}